package org.aaron.wbclient;

import java.util.HashMap;
import java.util.Map;

import oauth.signpost.OAuth;

import org.aaron.wbclient.model.WeiBoAdapter;
import org.aaron.wbclient.model.WeiBoHomeList;
import org.aaron.wbclient.oauth.Constans;

import com.google.gson.Gson;

import android.app.ListActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;

public class HomeTimeLineActivity extends ListActivity {
	private SharedPreferences preferences;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initActivity();
	}

	private void initActivity() {
		preferences = PreferenceManager.getDefaultSharedPreferences(this);
		WeiboClientOperate weiboClientOperate = new WeiboClientOperate(Constans.CONSUMER_KEY, Constans.CONSUMER_SECRET, preferences.getString(OAuth.OAUTH_TOKEN, ""), preferences.getString(
				OAuth.OAUTH_TOKEN_SECRET, ""));
		Map<String, String> additionalParams = new HashMap<String, String>();
		additionalParams.put("format", "json");
		additionalParams.put("pageflag", "0");
		additionalParams.put("pagetime", "0");
		additionalParams.put("reqnum", "20");
		additionalParams.put("type", "0");
		additionalParams.put("contenttype", "0x80");

		String result = weiboClientOperate.doGet(Constans.TENTENT_WEIBO_API.TENCENTWEIBO_HOME_TIMELINE_URL, additionalParams);
		Gson gson = new Gson();
		WeiBoHomeList weiBoHomeList = gson.fromJson(result, WeiBoHomeList.class);
		Log.d("WeiBoHomeList :", weiBoHomeList.toString());
		WeiBoAdapter adapter = new WeiBoAdapter(weiBoHomeList, this);
		getListView().setAdapter(adapter);
	}

}
